import { Button, Divider, Form, Input, InputNumber, Message, Modal, Radio, Select } from '@arco-design/web-react';
import { ReactNode } from 'react';
import { LoginUser,CardDetailConvert,PayMchManageDetail,DictData } from '../types';

import { dictDataOptions,validEmail, validTel } from '../utils/utils';
import DetailItem from './detailItem';
const { Item } = Form;
interface Props {
  title?: string;
  content?: ReactNode;
  okText?: string;
  cancelText?: string;
  hideCancel?: boolean;
  hideCloseIcon?: boolean;
  disableMaskClose?: boolean;
  type?: 'info' | 'warning' | 'success' | 'error';
}
// 通用确认取消弹窗
export function confirmDialog({
  title,
  content,
  okText,
  cancelText,
  hideCancel,
  disableMaskClose,
  hideCloseIcon,
  type = 'info',
}: Props) {
  return new Promise((resolve) => {
    Modal.confirm({
      title: title ?? '提示',
      content: content ?? '',
      okText: okText ?? '确定',
      cancelText: cancelText ?? '取消',
      simple: false,
      closable: !hideCloseIcon,
      hideCancel: hideCancel,
      maskClosable: !disableMaskClose,
      onCancel: () => resolve(0),
      onConfirm: () => resolve(1),
    });
  });
}

// 重置当前用户密码弹窗
export function resetPwdDialog() {
  return new Promise((resolve) => {
    let npwd = '';
    let nnpwd = '';
    function handleConfirm() {
      let reg = /^[0-9a-zA-Z]{6,20}$/;
      if (!npwd) {
        Message.warning('请输入新密码');
        resolve(0);
      } else if (!nnpwd) {
        Message.warning('请再次输入新密码');
        resolve(0);
      } else if (npwd && npwd !== nnpwd) {
        Message.warning('两次密码不一致');
        resolve(0);
      } else if (!reg.test(npwd)) {
        Message.warning('新密码只允许字母和数字组合,最少6位,最多20位');
        resolve(0);
      } else {
        resolve(npwd);
      }
    }
    Modal.warning({
      title: '重置密码',
      content: (
        <div>
          <Item label="新密码">
            <Input className="m-input" placeholder="请输入新密码" onChange={(v) => (npwd = v)} />
          </Item>
          <Item label="确认密码">
            <Input className="m-input" placeholder="请再次输入新密码" onChange={(v) => (nnpwd = v)} />
          </Item>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 重置用户密码弹窗
export function resetUserPwdDialog(name: string) {
  return new Promise((resolve) => {
    let pwd = '';
    function handleConfirm() {
      let reg = /^[0-9a-zA-Z]{6,20}$/;
      if (!pwd) {
        resolve(0);
      } else if (!reg.test(pwd)) {
        Message.warning('新密码只允许字母和数字组合,最少6位,最多20位');
      } else {
        resolve(pwd);
      }
    }
    Modal.warning({
      title: '重置密码',
      content: (
        <div>
          <div className="mb-20">请输入"{name}"的新密码</div>
          <Input className="m-input" placeholder="请输入密码" onChange={(v) => (pwd = v)} />
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 更新当前用户信息
export function updateAccountDialog(user: LoginUser, sexData: DictData[]) {
  return new Promise((resolve) => {
    let nickName = user.nickName ?? '';
    let email = user.email ?? '';
    let phonenumber = user.phonenumber ?? '';
    let sex = user.sex ?? '';
    function handleConfirm() {
      if (email && !validEmail(email)) {
        Message.warning('邮箱格式不正确');
        resolve(0);
      } else if (phonenumber && !validTel(phonenumber)) {
        Message.warning('手机号格式不正确');
        resolve(0);
      } else {
        resolve({ nickName, email, phonenumber, sex });
      }
    }
    Modal.info({
      title: '修改个人信息',
      content: (
        <div>
          <Item label="昵称">
            <Input
              className="m-input"
              defaultValue={nickName}
              placeholder="请输入昵称"
              onChange={(v) => (nickName = v)}
            />
          </Item>
          <Item label="手机号">
            <Input
              className="m-input"
              defaultValue={phonenumber}
              placeholder="请输入手机号"
              onChange={(v) => (phonenumber = v)}
            />
          </Item>
          <Item label="邮箱">
            <Input className="m-input" defaultValue={email} placeholder="请输入邮箱" onChange={(v) => (email = v)} />
          </Item>
          <Item label="性别">
            <Select
              className="m-select"
              defaultValue={sex}
              placeholder="请选择性别"
              options={dictDataOptions(sexData)}
              onChange={(v) => (sex = v)}
            />
          </Item>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 输入框弹窗
export function inputDialog(value?: string, title?: string, required?: boolean) {
  return new Promise<string | number>((resolve) => {
    let _value = value ?? '';
    function handleConfirm() {
      if (required && !_value) {
        Message.warning('请输入' + title);
        resolve(0);
      } else {
        resolve(_value);
      }
    }
    let _title = title ?? '内容';
    Modal.info({
      title: _title,
      content: (
        <div>
          <DetailItem required={required} label={_title} labelSpan={6} outlet={4}>
            <Input
              className="m-input"
              defaultValue={value}
              placeholder={'请输入' + _title}
              onChange={(v) => (_value = v)}
            />
          </DetailItem>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 修改授信额度
export function addShopreditDialog(title: string) {
  return new Promise((resolve) => {
    let creditLines: number | undefined = undefined;
    let remark = '';
    function handleConfirm() {
      if (!creditLines) {
        resolve(0);
      } else {
        resolve({ creditLines, remark });
      }
    }
    Modal.info({
      title: '添加授信额度',
      content: (
        <div>
          <Item label="店铺">
            <div>{title}</div>
          </Item>
          <Item label="授信额度">
            <InputNumber
              className="m-input"
              defaultValue={creditLines}
              placeholder="请输入授信额度"
              onChange={(v) => (creditLines = v)}
            />
          </Item>
          <Item label="备注">
            <Input.TextArea
              maxLength={200}
              showWordLimit
              className="m-input"
              autoSize={{ minRows: 4 }}
              defaultValue={remark}
              placeholder="请输入备注"
              onChange={(v) => (remark = v)}
            />
          </Item>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 号卡订单批量入队弹窗 选择供应商
export function batchTeamDialog(list: Array<{ label: string; value: string | number }>): Promise<string | number> {
  return new Promise((resolve) => {
    let value = '';
    function handleConfirm() {
      if (!value) {
        Message.warning('请选择供应商');
      } else {
        resolve(value);
      }
    }
    Modal.info({
      title: '批量入队',
      content: (
        <DetailItem required label="选择供应商" labelSpan={6} outlet={4}>
          <Select
            className="m-select"
            showSearch
            filterOption={(inputValue, option) =>
              option.props.value.toLowerCase().indexOf(inputValue.toLowerCase()) >= 0 ||
              option.props.children.toLowerCase().indexOf(inputValue.toLowerCase()) >= 0
            }
            options={list}
            onChange={(v) => (value = v)}
          />
        </DetailItem>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

//  修改备注
export function updateRemarkDialog(remark?: string, title?: string, required?: boolean) {
  return new Promise<string | number | undefined>((resolve) => {
    let _remark = remark;

    function handleConfirm() {
      if (required && !_remark) {
        Message.warning(title + '必填');
        resolve(0);
      } else {
        resolve(_remark);
      }
    }
    Modal.info({
      title: title ?? '修改备注',
      content: (
        <DetailItem label={title ?? '备注'} required={required} labelSpan={6} outlet={4}>
          <Input.TextArea
            className="m-input"
            defaultValue={remark}
            autoSize={{ minRows: 4, maxRows: 8 }}
            placeholder={'请输入' + (title ?? '备注')}
            onChange={(v) => (_remark = v)}
          />
        </DetailItem>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 转卡 审批
export function cardExamineDialog() {
  return new Promise<{ res: number; remark: string }>((resolve) => {
    let remark = '';
    let _info: any;
    function handleConfirm(r: number) {
      _info.close();
      resolve({ res: r, remark });
    }
    _info = Modal.info({
      title: '审批',
      className: 'p-0',
      content: (
        <>
          <Divider />
          <div className="pr-20 pl-20">
            <DetailItem label="审批备注" labelSpan={5} outlet={4}>
              <Input.TextArea
                className="m-input"
                autoSize={{ minRows: 3, maxRows: 5 }}
                defaultValue={remark}
                placeholder="请输入备注"
                onChange={(v) => (remark = v)}
              />
            </DetailItem>
          </div>
        </>
      ),
      footer: (
        <>
          <Divider />
          <div className="d-flex-r jc-end pr-20 pb-20">
            <Button className="ml-20" onClick={() => handleConfirm(0)}>
              关闭
            </Button>
            <Button className="ml-20" type="primary" status="danger" onClick={() => handleConfirm(1)}>
              拒绝
            </Button>
            <Button className="ml-20" type="primary" onClick={() => handleConfirm(2)}>
              同意
            </Button>
          </div>
        </>
      ),
    });
  });
}

// 转卡 填写快递单号等信息
export function cardReplaceCardDialog(record: CardDetailConvert) {
  return new Promise((resolve) => {
    let expressNo = record.expressNo;
    let expressName = record.expressName;
    let newIccid = record.newIccid;

    function handleConfirm() {
      if (!expressNo) {
        Message.warning('快递单号不能为空');
      } else if (!expressName) {
        Message.warning('快递名称不能为空');
      } else if (!newIccid) {
        Message.warning('新卡号不能为空');
      } else {
        resolve({ expressNo, expressName, newIccid });
      }
    }
    Modal.info({
      title: '发货信息',
      content: (
        <div className="d-flex-r bw-100 flex-wrap">
          <DetailItem required label="快递单号" labelSpan={5} outlet={4}>
            <Input
              className="m-input"
              defaultValue={expressNo}
              placeholder="请输入快递单号"
              onChange={(v) => (expressNo = v)}
            />
          </DetailItem>
          <DetailItem required label="快递名称" labelSpan={5} outlet={4}>
            <Input
              className="m-input"
              defaultValue={expressName}
              placeholder="请输入快递名称"
              onChange={(v) => (expressName = v)}
            />
          </DetailItem>
          <DetailItem required label="新卡号" labelSpan={5} outlet={4}>
            <Input
              className="m-input"
              defaultValue={newIccid}
              placeholder="请输入新卡号"
              onChange={(v) => (newIccid = v)}
            />
          </DetailItem>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 转卡 转卡
export function cardSwapCardDialog(remark?: string) {
  return new Promise((resolve) => {
    let newIccid = '';
    function handleConfirm() {
      resolve(newIccid);
    }
    Modal.info({
      title: '确认新卡号',
      content: (
        <DetailItem label="新卡号" labelSpan={4} outlet={4}>
          <Input
            className="m-input"
            defaultValue={newIccid}
            placeholder="请输入新卡号"
            onChange={(v) => (newIccid = v)}
          />
        </DetailItem>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 旧集卡数据导入
export function cardImportOldJKDialog(deptList: Array<{ label: string | number; value: string | number }>) {
  return new Promise((resolve) => {
    let names = '';
    let dept = '';
    function handleConfirm() {
      resolve({ dept, names });
    }
    Modal.info({
      title: '和云享导入',
      content: (
        <>
          <DetailItem label="部门" labelSpan={4} outlet={4}>
            <Select className="m-select" options={deptList} placeholder="部门" onChange={(v) => (dept = v)} />
          </DetailItem>
          <DetailItem label="用户" labelSpan={4} outlet={4}>
            <Input.TextArea
              className="m-input"
              autoSize={{ minRows: 8, maxRows: 20 }}
              placeholder="请输入ICCID"
              onChange={(v) => (names = v)}
            />
          </DetailItem>
        </>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 退款原因 修改原因
export function cardDetailWalletRefundReasonDialog(title?: string, remark?: string) {
  return new Promise((resolve) => {
    let _remark = '';
    function handleConfirm() {
      resolve(_remark);
    }
    Modal.info({
      title: title ? title : '修改原因',
      content: (
        <DetailItem label={title ? title : '原因'} labelSpan={4} outlet={4}>
          <Input
            className="m-input"
            defaultValue={remark}
            placeholder={title ? `请输入${title}` : '请输入退款原因'}
            onChange={(v) => (_remark = v)}
          />
        </DetailItem>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 添加资产管理下产品商的通道
export function addAssetsSupplierProductDialog(list: Array<{ label: string; value: number }>) {
  return new Promise((resolve) => {
    let supplierProductId: number;
    let flowPrice = 0;
    let cardPrice = 0;
    function handleConfirm() {
      if (!supplierProductId) {
        Message.warning('请选择通道');
        resolve(0);
      } else if (!flowPrice) {
        Message.warning('请填写流量单价');
        resolve(0);
      } else if (!cardPrice) {
        Message.warning('请填写卡板价格');
        resolve(0);
      } else {
        let _t = list.find((i) => i.value === supplierProductId);
        resolve({ supplierProductId, supplierProductName: _t?.label, flowPrice, cardPrice });
      }
    }
    Modal.info({
      title: '添加通道',
      content: (
        <div className="d-flex-r bw-100 flex-wrap">
          <DetailItem label="通道" required labelSpan={5} outlet={4}>
            <Select
              showSearch
              filterOption={(iv, option) => option.props.children.includes(iv)}
              className="m-select"
              placeholder="请选择通道"
              options={list}
              onChange={(v) => (supplierProductId = v)}
            />
          </DetailItem>
          <DetailItem label="流量单价" required labelSpan={5} outlet={4}>
            <InputNumber className="m-input" placeholder="请输入流量单价" onChange={(v) => (flowPrice = v)} />
          </DetailItem>
          <DetailItem label="卡板价格" required labelSpan={5} outlet={4}>
            <InputNumber className="m-input" placeholder="请输入卡板价格" onChange={(v) => (cardPrice = v)} />
          </DetailItem>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 编辑资产管理下产品商的通道
export function editAssetsSupplierProductDialog(fprice?: number, cprice?: number) {
  return new Promise((resolve) => {
    let flowPrice = fprice;
    let cardPrice = cprice;
    function handleConfirm() {
      if (!flowPrice) {
        Message.warning('请填写流量单价');
        resolve(0);
      } else if (!cardPrice) {
        Message.warning('请填写卡板价格');
        resolve(0);
      } else {
        resolve({ flowPrice, cardPrice });
      }
    }
    Modal.info({
      title: '编辑通道',
      content: (
        <div className="d-flex-r bw-100 flex-wrap">
          <DetailItem label="流量单价" required labelSpan={5} outlet={4}>
            <InputNumber
              className="m-input"
              defaultValue={flowPrice}
              placeholder="请输入流量单价"
              onChange={(v) => (flowPrice = v)}
            />
          </DetailItem>
          <DetailItem label="卡板价格" required labelSpan={5} outlet={4}>
            <InputNumber
              className="m-input"
              defaultValue={cardPrice}
              placeholder="请输入卡板价格"
              onChange={(v) => (cardPrice = v)}
            />
          </DetailItem>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 卡详情操作余额
export function cardDetailOperationBalanceDialog(iccid: string, balance: number, dict: DictData[]) {
  return new Promise((resolve) => {
    let type = 'backgroundSub';
    let amount = 0;
    let remark = '';
    function handleConfirm() {
      if (!type) {
        Message.warning('请选择操作类型');
        resolve(0);
      } else if (!amount) {
        Message.warning('请填写操作金额');
        resolve(0);
      } else if (!remark) {
        Message.warning('请填写备注');
        resolve(0);
      } else {
        resolve({ type, amount, remark });
      }
    }
    let canUseType = ['orderEquipment', 'rechargeNumberCard', 'backgroundSub'];
    let types = dict.filter((i) => canUseType.includes(i.dictValue!));
    Modal.info({
      title: `【${iccid}】余额操作`,
      content: (
        <div className="d-flex-r bw-100 flex-wrap">
          <DetailItem label="现有余额" required labelSpan={5} outlet={4}>
            <span>{balance}元</span>
          </DetailItem>
          <DetailItem label="操作类型" required labelSpan={5} outlet={4}>
            <Radio.Group options={dictDataOptions(types)} defaultValue={type} onChange={(v) => (type = v)} />
          </DetailItem>
          <DetailItem label="操作金额" required labelSpan={5} outlet={4}>
            <InputNumber
              className="m-input"
              min={0}
              max={balance}
              defaultValue={amount}
              onChange={(v) => (amount = v)}
            />
          </DetailItem>
          <DetailItem label="备注" required labelSpan={5} outlet={4}>
            <Input.TextArea className="m-input" autoSize={{ minRows: 3 }} onChange={(v) => (remark = v)} />
          </DetailItem>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 提现弹窗
export function withdrawDialog(list: Array<{ label: string; value: string }>) {
  return new Promise<any>((resolve) => {
    let _amount = '';
    let _type = list[0].value;
    function handleConfirm() {
      if (!_type) {
        Message.warning('请选择提现类型');
        resolve(0);
      } else if (!_amount) {
        Message.warning('请输入提现金额');
        resolve(0);
      } else {
        resolve({ amount: _amount, transferType: _type });
      }
    }

    Modal.info({
      title: '提现',
      content: (
        <div>
          <DetailItem required label="提现类型" labelSpan={5} outlet={4}>
            <Radio.Group defaultValue={_type} options={list} onChange={(v) => (_type = v)} />
          </DetailItem>
          <DetailItem required label="提现金额" labelSpan={5} outlet={4}>
            <Input className="m-input" placeholder="请输入提现金额" onChange={(v) => (_amount = v)} />
          </DetailItem>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 修改防超系数
export function cardDetailFlowScaleDialog(
  flow: string,
  iccid: string,
  recordList?: { createTime?: string; businessText?: string; remark?: string }
) {
  return new Promise((resolve) => {
    let flowScale = flow ?? '';
    function handleConfirm() {
      resolve({ flowScale });
    }
    Modal.info({
      title: `【${iccid}】防超系数操作`,
      content: (
        <div className="d-flex-r bw-100 flex-wrap">
          <div className="mb-10 ml-30">
            <span className="mr-10">{recordList?.createTime}</span>
            <span className="mr-10">{recordList?.businessText}</span>
          </div>
          <DetailItem label="防超系数" labelSpan={5} outlet={4}>
            <Input defaultValue={flowScale} onChange={(v) => (flowScale = v)} />
          </DetailItem>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 转卡换卡-修改聚水潭商品ID
export function cardEditJstDialog(
  deptList: Array<{ label: string | number; value: string | number }>,
  goodsId: string | undefined
) {
  return new Promise((resolve) => {
    let jstGoodsNo = goodsId;
    function handleConfirm() {
      resolve({ jstGoodsNo });
    }
    Modal.info({
      title: '修改聚水潭订单ID',
      content: (
        <>
          <DetailItem label="修改聚水潭" labelSpan={4} outlet={4}>
            <Select className="m-select" defaultValue={goodsId} options={deptList} onChange={(v) => (jstGoodsNo = v)} />
          </DetailItem>
        </>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 查询卡片冻结情况
export function cardDetailFreezeInfoDialog(data: any) {
  return new Promise((resolve) => {
    Modal.info({
      title: '查询卡片冻结情况',
      content: (
        <>
          <DetailItem label="是否冻结" labelSpan={5} outlet={4}>
            <span>{data.manageStopRestartStatus === '1' ? '是' : '否'}</span>
          </DetailItem>
          <DetailItem label="原因" labelSpan={5} outlet={4}>
            <Input.TextArea disabled rows={3} className="m-input" defaultValue={data.reason} />
          </DetailItem>
          <DetailItem label="冻结时间" labelSpan={5} outlet={4}>
            <Input disabled className="m-input" defaultValue={data.manageStopRestartStatusTime} />
          </DetailItem>
        </>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: () => resolve(0),
    });
  });
}

// 输入操作密码
export function checkSecondPwdDialog() {
  return new Promise((resolve) => {
    let secondPassword = '';
    function handleConfirm() {
      if (!secondPassword) {
        Message.warning('请输入操作密码');
        resolve(0);
      } else if (secondPassword.length > 11 || secondPassword.length < 6) {
        Message.warning('请输入符合6-11位数字，大小写字母任意组合的密码');
      } else {
        return resolve({ secondPassword });
      }
    }
    Modal.info({
      title: '操作密码',
      content: (
        <>
          <DetailItem label="操作密码" labelSpan={5} outlet={4}>
            <Input defaultValue={secondPassword} onChange={(v) => (secondPassword = v)} />
          </DetailItem>
        </>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

/**
 * 批量指派人员弹窗
 * cardWorkOrder
 * @param list
 * @returns
 */
export function batchDispatchUserDialog(
  list: Array<{ label: string; value: string }>
): Promise<number | { userId: string; userName: string }> {
  return new Promise((resolve) => {
    let userId = '';
    let userName = '';
    function handleConfirm() {
      if (!userId) {
        Message.warning('请选择指派人员');
        resolve(0);
      } else {
        resolve({ userId, userName });
      }
    }
    Modal.info({
      title: '批量指派人员',
      content: (
        <>
          <DetailItem label="选择人员" labelSpan={5} outlet={4}>
            <Select
              className="m-select"
              options={list}
              onChange={(v, option: any) => {
                userId = v;
                userName = option.children;
              }}
            />
          </DetailItem>
        </>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 商户余额-余额操作
export function changeBalanceDialog(list: Array<{ label: string; value: string }>, record: PayMchManageDetail) {
  return new Promise<any>((resolve) => {
    let operateBalance: string | number = '',
      remark = record.remark;
    let operateType = list[0].value;
    function handleConfirm() {
      if (!operateType) {
        Message.warning('请选择提现类型');
        resolve(0);
      } else if (!operateBalance) {
        Message.warning('请输入金额');
        resolve(0);
      } else {
        resolve({ operateBalance, operateType, remark });
      }
    }

    Modal.info({
      title: `商户名称【${record.mchName}】余额操作`,
      content: (
        <div>
          <DetailItem required label="操作类型" labelSpan={5} outlet={4}>
            <Radio.Group defaultValue={operateType} options={list} onChange={(v) => (operateType = v)} />
          </DetailItem>
          <DetailItem required label="金额" labelSpan={5} outlet={4}>
            <InputNumber
              min={0}
              step={0.01}
              precision={1}
              className="m-input"
              placeholder="请输入金额"
              onChange={(v) => (operateBalance = v)}
            />
          </DetailItem>
          <DetailItem label="备注" labelSpan={5} outlet={4}>
            <Input.TextArea
              autoSize={{ minRows: 2, maxRows: 3 }}
              className="m-input"
              value={remark}
              onChange={(v) => (remark = v)}
            />
          </DetailItem>
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: handleConfirm,
    });
  });
}

// 申请发票-存在退款的流水号
export function getRefundTransactionDialog(title: string, data: string[]) {
  return new Promise<number>((resolve) => {
    Modal.info({
      title: title,
      content: (
        <div className="d-flex-c">
          <div>以下流水处于退款申请中，无法开具发票：</div>
          {data.map((item, idx) => (
            <div key={idx} className="mt-3">
              {item}
            </div>
          ))}
        </div>
      ),
      okText: '确定',
      cancelText: '取消',
      simple: false,
      escToExit: true,
      onCancel: () => resolve(0),
      onConfirm: () => resolve(0),
    });
  });
}

// 换卡订单-取消订单
export function convertOrderConfirmDialog(title: string, content: string) {
  return new Promise((resolve) => {
    Modal.confirm({
      title: title,
      content: <div className="bw-100" dangerouslySetInnerHTML={{ __html: content ?? '' }}></div>,
      simple: false,
      onCancel: () => resolve(0),
      onConfirm: () => resolve(1),
    });
  });
}
